﻿@using  RooHui.Infrastructure.Entities.Entity;
@using RooHui.Tool;
@{
    ViewBag.Title = "ProcessStepList";
    Layout = "~/Views/Shared/_Base.cshtml";
    ProcessDef processDef = ViewBag.processDef; 
}
@section head{
    <script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.metadata.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/roohui/jquery-validation/messages_cn.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Content/operate/processstepmanage.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {


            $("#currentProcess").ligerComboBox(
                {
                    url: '/Process/GetProcessListByDefID?defID='+@processDef.ID,
                    valueField: 'ID',
                    textField: 'ProcessName',
                    autocomplete: true
                }
            );
               $("#nextProcess").ligerComboBox(
                {
                    url: '/Process/GetProcessListByDefID?defID='+@processDef.ID+"&type=1",
                    valueField: 'ID',
                    textField: 'ProcessName',
                    autocomplete: true
                }
            );  
             
        });
    </script>
}
<div id="toptoolbar" style="width: 100%">
</div> 
<div id="processstepgrid">
</div>
<input type="hidden" name="processdefID" id="processdefID" value="@processDef.ID" />
<form action="/" method="post" id="frmProcessStep" name="frmProcessStep" style="background-color: white;
display: none">
    <table cellpadding="0" cellspacing="0" class="l-table-edit" width="100%">
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;当前节点:
            </td>
            <td align="left" class="l-table-edit-td" >
             
                <input type="text" id="currentProcess" class="l-text-field" validate="{required:true}"/>
               
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;下一节点:
            </td>
            <td align="left" class="l-table-edit-td">
                   <input type="text" id="nextProcess" class="l-text-field" validate="{required:true}"/>
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;逻辑条件:
            </td>
            <td align="left" class="l-table-edit-td">
                  <input name="txtProcessStepName" type="text" id="txtProcessStepName" class="l-text-field" validate="{required:true}"/>
            </td>
            <td align="left">
            </td>
        </tr>
        
         
        <tr>
        <td align="right" class="l-table-edit-td">
                &nbsp;
            </td>
        <td align="left" colspan="2">
            <span id="lblmsg" class="l-validate-error">&nbsp;</span>
            <input type="hidden" name="processStepID" id="processStepID" value="0" />
        </td>
    </tr>
    </table>
</form>
<script type="text/javascript">
    var processstepgrid;
    var saveDialog;
    $(function () {
        //selType = $("#selType").ligerComboBox();

        $("#toptoolbar").ligerToolBar({ items: [{ text: '新增', click: grid_processstep_add, icon: "add" },
            { text: '修改', click: grid_processstep_edit, icon: "modify" },
            { text: '删除', click: grid_processstep_delete, icon: "delete" },
            { text: '刷新', click: grid_processstep_refresh, icon: "refresh" },
            { text: '返回', click: grid_processstep_back, icon: "prev" }
            ]
        });
        processstepgrid = $("#processstepgrid").ligerGrid({
            columns: [
                
                { display: '逻辑条件', name: 'StepName', width: '25%', isSort: false },
                { display: '当前节点', name: 'CurrentProcessID', width: '20%', isSort: false,
                    render: function (item) {
                        if(item.CurrentProcessID==-1){
                            return "开始";
                        } 
                        else
                        {
                            
                            return item.CurrentProcess.ProcessName;
                        }
                    }
                }, 
                { display: '下一节点', name: 'NextProcessID', width: '20%', isSort: false,
                    render: function (item) { 
                    if(item.NextProcessID==-1){
                            return "结束";
                        } 
                        else
                        { 
                            return item.NextProcess.ProcessName;
                        }
                    }
                }, 
                 
                { display: '状态', name: 'Status', width: '10%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.Status) == 1) return '正常';
                        return '禁用';
                    }
                },
                {
                    display: '操作', isAllowHide: false,
                    render: function (row) {

                        var html = '<a href="#" onclick="grid_processstep_show(\'' + row.StepName + '\',\'' + row.CurrentProcessID + '\',\'' + row.NextProcessID + '\',\'' + row.ID + '\')">修改</a>&nbsp;&nbsp;<a href="#" onclick="processstep_delete(\'' + row.ID + '\',\'' + row.StepName + '\')">删除</a>';
                        
                        return html;
                    }
                }
                ],
            width: '100%', height: '100%', rownumbers: true,
            dataAction: 'server',
            url: "/Process/GetProcessStepListByPageAndDefID?defID="+@processDef.ID,
            pageSizeOptions: [10],
            pageSize: 10
        });
        $.metadata.setType("attr", "validate");
        var v = $("#frmProcessStep").validate({
            //debug: true,
            errorPlacement: function (lable, element) {
                if (element.hasClass("l-textarea")) {
                    element.ligerTip({ content: lable.html(), target: element[0] });
                }
                else if (element.hasClass("l-text-field")) {
                    element.parent().ligerTip({ content: lable.html(), target: element[0] });
                }
                else {
                    lable.appendTo(element.parents("td:first").next("td"));
                }
            },
            success: function (lable) {
                lable.ligerHideTip();
                lable.remove();
            },
            submitHandler: function () {
                 
                var currentProcess = liger.get("currentProcess").getValue();
                var nextProcess = liger.get("nextProcess").getValue();
                 
                if (currentProcess== "") {
                    $('#currentProcess').focus();
                    $("#lblmsg").html('当前节点不能为空');
                    return;
                }
                if (nextProcess== "") {
                    $('#nextProcess').focus();
                    $("#lblmsg").html('下一节点不能为空');
                    return;
                }
                if ($('#txtProcessStepName').val() == "") {
                    $('#txtProcessStepName').focus();
                    $("#lblmsg").html('逻辑条件不能为空');
                    return;
                }
                $.ajax({
                    url: "/Process/ProcessStepSave",
                    data: "processDefID=" + $("#processdefID").val() + "&stepName=" + $('#txtProcessStepName').val()
                    + "&currentProcessID=" + currentProcess + "&nextProcessID=" + nextProcess + "&processStepID=" + $("#processStepID").val(),
                    type: "post",
                    success: function (result) {
                        //写提交ajax操作
                        if (result == "1") {
                            $.ligerDialog.success("保存成功。");
                            processstep_reset();
                            saveDialog.hide();
                            grid_processstep_refresh();
                        }
                        else {
                            if (result == "-1") {
                                $.ligerDialog.error("审批条件已存在!");
                            }
                            else {
                                $.ligerDialog.error("保存失败。");
                            }
                        }

                    }
                });
            }
        });
        $("#frmProcessStep").ligerForm();
    }); 
</script>